Week 2 Deep Internal Analysis: Memory Physics & Hex Grids
Section 1: Memory Physics & Hexadecimal Grid Mechanics
Peering beneath the operational layer of the operating system kernel (Under the Hood), we discover that Random Access Memory (RAM) functions physically as an immense matrix of byte-sized memory cells. Each discrete cell consists of micro-transistors and capacitors holding electrical charge states representing physical 0s and 1s. To differentiate these individual cells, the CPU allocates a unique numerical identifier to every byte, canonically represented in hexadecimal notation, such as 0x120, 0x121, 0x122.
===================================================================================
DEEP HARDWARE MEMORY MAP (HEXADECIMAL ALLOCATION)
===================================================================================
[ Address: 0x100 ] ββ> int (Byte 1) β
[ Address: 0x101 ] ββ> int (Byte 2) ββ 4 Contiguous Bytes (e.g., scores[0])
[ Address: 0x102 ] ββ> int (Byte 3) β
[ Address: 0x103 ] ββ> int (Byte 4) β
[ Address: 0x104 ] ββ> char (Byte 1) ββ> 1 Byte (e.g., 'H')
[ Address: 0x105 ] ββ> char (Byte 2) ββ> 1 Byte (e.g., 'I')
[ Address: 0x106 ] ββ> char (Byte 3) ββ> 1 Byte (e.g., '\0' Null Terminator)
===================================================================================
- Contiguous Memory Allocation of Arrays: In bare-metal C, an array is not an encapsulated object; rather, it acts fundamentally as a direct pointer referencing the base address of its initial element.
- Pointer Offset Calculation: When evaluating an indexed access such as
scores[2], the CPU dynamically computes the absolute target address using the base address and data type size offset.
Section 2: Deep String Anatomy & Pointer Deconstruction
In bare-metal C architecture, a string is literally implemented as a char * (a memory pointer holding the base address of a character array).
===================================================================================
DEEP STRING POINTER EXECUTION MATRIX
===================================================================================
string s = "HI!"; (CS50 wrapper) ββ> char *s = "HI!"; (Bare metal C)
[ Pointer s ] ββ> Holds address 0x104
β
βΌ
[ 0x104: 'H' ] ββ> [ 0x105: 'I' ] ββ> [ 0x106: '!' ] ββ> [ 0x107: '\0' ]
===================================================================================
- The Critical Function of \0: Because the bare-metal compiler retains no runtime metadata tracking array length, the null terminator
\0serves as the sole physical boundary preventing the CPU from performing a buffer over-read into adjacent memory domains. - Physical Execution of strlen: The standard library function
strlenexecutes a linear while loop that increments an internal pointer across consecutive memory addresses until encountering the exact byte value 0. Consequently, the time complexity of string length evaluation is strictly O(n).
Section 3: Mathematical Parsing Analysis & Cryptography
The Coleman-Liau index computes academic reading levels utilizing a mathematical formulation tracking average letters and sentences per 100 words.
- Caesar Cipher Mathematical Mechanics: The cryptographic transformation relies on strict modular arithmetic
c = (p + k) % 26.